package com.suixun.controller;


import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.authority.controller.BaseManager;
import com.google.gson.Gson;
import com.suixun.service.UserQuestionService;
import com.suixun.util.Constant;
import com.suixun.util.StringUtil;
import com.suixun.vo.ReplyMessageVO;
import com.suixun.vo.UserQuestionVO;

/**
 * 
 * <p>Title: UserQuestionController</p>
 * <p> 功能描述:反馈管理 </p> 
 * @author	陈显强
 * @date	2017年3月6日下午4:37:25
 * @version 1.0
 */
@Controller
@RequestMapping("/userQuestionManage")
public class UserQuestionController extends BaseManager {
	@Resource
	private UserQuestionService userQuestionService;

	/**
	 * <p>Title: queryUserQuestionList</p>
	 * <p> 功能描述:查询用户反馈信息 </p>
	 * @param param
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/queryUserQuestionList.json")
	public Object queryUserQuestionList(String param) {
		boolean bln = checkRight();
		if (!bln) {
			return fail(Constant.Authority.CHECK_FALSE);
		}
		try {
			UserQuestionVO question = null;
			if (StringUtil.isEmpty(param)) {
				question = new UserQuestionVO();
			}else {
				question = new Gson().fromJson(param, UserQuestionVO.class);
			}
			return success(userQuestionService.queryQuestionList(question));
		} catch (Exception e) {
			logger("UserQuestionController queryUserQuestionList:"+e.getMessage(),e);
			return fail(Constant.EXCEPTION.OPERATE_FAIL);
		}
	}
	/**
	 * <p>Title: queryUserQuestion</p>
	 * <p> 功能描述:查询指定反馈信息 </p>
	 * @param param
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/queryUserQuestion.json")
	public Object queryUserQuestion(String param) {
		boolean bln = checkRight();
		if (!bln) {
			return fail(Constant.Authority.CHECK_FALSE);
		}
		try {
			if (StringUtil.isEmpty(param)) {
				return fail(Constant.EMPTY);
			}
			UserQuestionVO	question = new Gson().fromJson(param, UserQuestionVO.class);
			if (question.getId() == null) {
				return fail(Constant.EMPTY);
			}
			return success(userQuestionService.queryQuestion(question));
		} catch (Exception e) {
			logger("UserQuestionController queryUserQuestion:"+e.getMessage(),e);
			return fail(Constant.EXCEPTION.OPERATE_FAIL);
		}
	}

	/**
	 * <p>Title: resolveByTel</p>
	 * <p> 功能描述:电话处理 </p>
	 * @param param
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/resolveByTel.json")
	public Object resolveByTel(String param) {
		boolean bln = checkRight();
		if (!bln) {
			return fail(Constant.Authority.CHECK_FALSE);
		}
		if (StringUtil.isEmpty(param)) {
			return fail(Constant.EMPTY);
		}
		try {
			UserQuestionVO question = new Gson().fromJson(param, UserQuestionVO.class);
			if (question.getId() == null) {
				return fail(Constant.EMPTY);
			}
			int isUpdate = userQuestionService.resolveByTel(question.getId());
			if (isUpdate == 1) {
				return success();
			}
			return fail(Constant.OPERATE_FAIL);
		}catch (Exception e) {
			logger("UserQuestionController resolveByTel:"+e.getMessage(),e);
			return fail(Constant.EXCEPTION.OPERATE_FAIL);
		}
	}
	/**
	 * <p>Title: queryReplyMessageList</p>
	 * <p> 功能描述:查询回复详情 </p>
	 * @param param
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/queryReplyMessageList.json")
	public Object queryReplyMessageList(String param) {
		boolean bln = checkRight();
		if (!bln) {
			return fail(Constant.Authority.CHECK_FALSE);
		}
		if (StringUtil.isEmpty(param)) {
			return fail(Constant.EMPTY);
		}
		try {
			ReplyMessageVO replyMessage = new Gson().fromJson(param, ReplyMessageVO.class);
			if (replyMessage.getQuestionid() == null) {
				return fail(Constant.EMPTY);
			}
			return success(userQuestionService.getReplyMessageList(replyMessage.getQuestionid()));
		}catch (Exception e) {
			logger("UserQuestionController queryReplyMessageList:"+e.getMessage(),e);
			return fail(Constant.EXCEPTION.OPERATE_FAIL);
		}
	}
	/**
	 * <p>Title: replyMessage</p>
	 * <p> 功能描述:回复 </p>
	 * @param param
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/replyMessage.json")
	public Object replyMessage(String param) {
		boolean bln = checkRight();
		if (!bln) {
			return fail(Constant.Authority.CHECK_FALSE);
		}
		if (StringUtil.isEmpty(param)) {
			return fail(Constant.EMPTY);
		}
		try {
			ReplyMessageVO replyMessage = new Gson().fromJson(param, ReplyMessageVO.class);
			if (replyMessage == null || replyMessage.getQuestionid() == null || StringUtil.isEmpty(replyMessage.getContent()) ) {
				return fail(Constant.EMPTY);
			}
			Integer isAdd = userQuestionService.replyMessage(replyMessage, getUserId());
			if (isAdd == 1) {
				return success();
			}
			return fail(Constant.OPERATE_FAIL);
		}catch (Exception e) {
			logger("UserQuestionController replyMessage:"+e.getMessage(),e);
			return fail(Constant.EXCEPTION.OPERATE_FAIL);
		}
	}
	/**
	 * <p>Title: deleteReplyMessage</p>
	 * <p> 功能描述:删除回复信息 </p>
	 * @param param
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/deleteReplyMessage.json")
	public Object deleteReplyMessage(String param) {
		boolean bln = checkRight();
		if (!bln) {
			return fail(Constant.Authority.CHECK_FALSE);
		}
		if (StringUtil.isEmpty(param)) {
			return fail(Constant.EMPTY);
		}
		try {
			ReplyMessageVO replyMessage = new Gson().fromJson(param, ReplyMessageVO.class);
			if (replyMessage.getId() == null) {
				return fail(Constant.EMPTY);
			}
			Integer isDelete = userQuestionService.deleteReplyMessage(replyMessage.getId());
			if (isDelete == 1) {
				return success();
			}
			return fail(Constant.OPERATE_FAIL);
		}catch (Exception e) {
			logger("UserQuestionController deleteReplyMessage:"+e.getMessage(),e);
			return fail(Constant.EXCEPTION.OPERATE_FAIL);
		}
	}
	/**
	 * <p>Title: deleteUserQuestion</p>
	 * <p> 功能描述:删除反馈信息 </p>
	 * @param param
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/deleteUserQuestion.json")
	public Object deleteUserQuestion(String param) {
		boolean bln = checkRight();
		if (!bln) {
			return fail(Constant.Authority.CHECK_FALSE);
		}
		if (StringUtil.isEmpty(param)) {
			return fail(Constant.EMPTY);
		}
		try {
			UserQuestionVO question = new Gson().fromJson(param, UserQuestionVO.class);
			if (question.getId() == null) {
				return fail(Constant.EMPTY);
			}
			Integer isDelete = userQuestionService.deleteUserQuestion(question.getId(),getUserId());
			if (isDelete == 1) {
				return success();
			}
			return fail(Constant.OPERATE_FAIL);
		}catch (Exception e) {
			logger("UserQuestionController deleteUserQuestion:"+e.getMessage(),e);
			return fail(Constant.EXCEPTION.OPERATE_FAIL);
		}
	}
	
}
